<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{{title}} - 图腾生命医学</title>
    <link href="/apps/css/bootstrap.min.css" rel="stylesheet">
    <link href="/apps/css/fontawesome-free-6.4.0-web/css/all.css" rel="stylesheet">
    <style>
        body { padding-top: 20px; }
        .form-label { font-weight: bold; }
    </style>
</head>
<body>
    <div class="container">
        <div class="row">
            <div class="col-md-12">
                <h3>{{title}}</h3>

                <form id="createSalesPlanForm" class="mt-4">
                    <div class="mb-3">
                        <label class="form-label">规划任务名称</label>
                        <input type="text" class="form-control" name="title" required 
                               placeholder="例如: 24年Q4总结及25年Q1计划">
                    </div>

                    <div class="mb-3">
                        <label class="form-label">规划任务说明</label>
                        <textarea class="form-control" name="description" rows="3" required
                                  placeholder="请详细描述规划任务的要求和目标"></textarea>
                    </div>

                    <div class="mb-3">
                        <label class="form-label">回顾周期</label>
                        <div class="row">
                            <div class="col">
                                <input type="date" class="form-control" name="review_start_date" required>
                                <small class="text-muted">开始日期</small>
                            </div>
                            <div class="col">
                                <input type="date" class="form-control" name="review_end_date" required>
                                <small class="text-muted">结束日期</small>
                            </div>
                        </div>
                    </div>

                    <div class="mb-3">
                        <label class="form-label">计划周期</label>
                        <div class="row">
                            <div class="col">
                                <input type="date" class="form-control" name="plan_start_date" required>
                                <small class="text-muted">开始日期</small>
                            </div>
                            <div class="col">
                                <input type="date" class="form-control" name="plan_end_date" required>
                                <small class="text-muted">结束日期</small>
                            </div>
                        </div>
                    </div>

                    <div class="mb-3">
                        <button type="submit" class="btn btn-primary">
                            <i class="fas fa-save"></i> 创建
                        </button>
                        <a href="/apps/crm/sales-plans" class="btn btn-secondary">
                            <i class="fas fa-arrow-left"></i> 返回
                        </a>
                    </div>
                </form>
            </div>
        </div>
    </div>

    <script src="/apps/js/jquery.min.js"></script>
    <script src="/apps/js/bootstrap.bundle.min.js"></script>
    <script>
    document.getElementById('createSalesPlanForm').addEventListener('submit', async (e) => {
        e.preventDefault();

        const formData = new FormData(e.target);
        const data = Object.fromEntries(formData.entries());

        try {
            const response = await fetch('/apps/crm/api/sales-plans', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json'
                },
                body: JSON.stringify(data)
            });

            if (!response.ok) throw new Error('创建失败');

            window.location.href = '/apps/crm/sales-plans';
        } catch (err) {
            alert('创建失败: ' + err.message);
        }
    });
    </script>
</body>
</html> 